const koa = require("koa")

const app = new koa()

// const {normal} = require("./tpl")

// const ejs = require("ejs")

const views = require("koa-views")

const { resolve } = require("path")

const { connect, initSchema } = require("./databases/init")

const mongoose = require("mongoose")


  ; (async () => {
    await connect()
    await initSchema()

    // require('./tasks/movie')//require之后就会自动去执行
    // require("./tasks/api")
  })()
const router = require('./router')

app
  .use(router.routes())
  .use(router.allowedMethods())


app.use(views(resolve(__dirname, "./views"), {
  extension: "pug" //只要是后缀名为pug的就会识别为模板文件
}))

app.use(async (ctx, next) => {
  await ctx.render("index", {
    you: "zhangyue",
    me: "yuezhang"
  })
})

console.log("开启成功")
app.listen(7788)

